
package org.lanqiao.tjut.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.UsersBean;
import org.lanqiao.tjut.bean.UsersBeanTea;
import org.lanqiao.tjut.myUtils.MyUtils;
import org.lanqiao.tjut.service.ServiceFactory;

public class UserTeaReviseStu extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 设置编码
		// req.setCharacterEncoding("UTF-8"); //已经使用filter进行了编码设置
		request.setCharacterEncoding("UTF-8");
		// 1、获取表单数据
		// 2、将保单数据填充到实体类
		// UsersBean usersB = (UsersBean)
		// MyUtils.getNewInstance(UsersBean.class);
		UsersBeanTea usersBT = new UsersBeanTea();
		// id
		//课程ID
		int list=MyUtils.obj2Int(request.getParameter("listLong"));
		
		usersBT.setCouid(MyUtils.obj2Integer(request.getParameter("selectCouid")));
		
		
		//学生ID  学生成绩
		for(int i=1;i<=list;i++){
		
		String Usernum="selectUsernum"+i;
		String Cousco="txtStuCousco"+i;
			
		usersBT.setUsernum(request.getParameter(Usernum));
		usersBT.setCousco(request.getParameter(Cousco));

		
		ServiceFactory.getUserInfoManagerTeaServiceInstance().saveUserInfo(usersBT);
	

		}
		String strUid = request.getParameter("selectCouid");
		List<UsersBeanTea> usersBTea = ServiceFactory.getUserInfoManagerTeaServiceInstance().getUserInfoById(strUid);
		// 数据保存成功
		// 准备一下在添加成功的页面上进行数据显示
		// 获取需要显示的所有的数据集合
		// 将需要显示的结果集放入session缓存中
		request.getSession().setAttribute("lstUsersTea", usersBTea);
		// 清空request缓存中的对象
		// 清空UsersBean
		request.removeAttribute("usersBT");
		// 转发到结果显示页面
		request.getRequestDispatcher("logined/UserInfoManager/UserTeaQueryStu.jsp").forward(request, response);
		// response.sendRedirect("logined/UserInfoManager/userInfoAddDetail.jsp");

	}

}
